<template>
    <div>
        <el-tabs type="border-card" style="margin-bottom:20px">
			<!-- <el-tab-pane label="Total">
				<el-row>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type4"
							:title="common.titles[0]"
							:num="String(labelsData.build)"
							:sub="common.subs[0]"
							:to_sub="common.to_sub"
							:cls="common.success">
                        </info_label>
					</el-col>
				</el-row>
			</el-tab-pane> -->
			<el-tab-pane label="Daily-build">
				<el-row :gutter="30">
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type4"
							:title="common.titles[0]"
							:num="String(labelsData['daily_build'])"
							:sub="common.subs[0]"
							:to_sub="common.to_sub"
							:cls="common.success"
						></info_label>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label_compare
							:params="generate_label_params(labelsData.daily_day_av_build, [true, 1], 'frequency', common.titles[29], common.type5)"
							:to_sub="common.avg + ' (目标>=1)'"
							:sub="common.subs[0]"
							:cls="common.success"
						></info_label_compare>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type4"
							:title="common.titles[28]"
							:num="String(labelsData.daily_build_success)"
							:sub="common.subs[0]"
							:to_sub="common.to_sub"
							:cls="common.success"
						></info_label>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label_compare
							:params="generate_label_params(labelsData.daily_av_success_rate, [true, 90], 'percent', common.titles[27], common.type5)"
							:to_sub="common.avg + ' (目标>=90%)'"
							:sub="common.subs[7]"
							:cls="common.success"
						></info_label_compare>
					</el-col>
				</el-row>
				<el-row :gutter="30">
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label_compare
							:params="generate_label_params(labelsData.daily_av_duration, [false, 90], 'time', common.titles[8], common.type5)"
							:to_sub="common.avg + ' (目标<=90分钟)'"
							:sub="common.subs[1]"
							:cls="common.success"
						></info_label_compare>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label_compare
							:params="generate_label_params(labelsData.daily_av_queue_time, [false, 5], 'time', common.titles[30], common.type5)"
							:sub="common.subs[1]"
							:to_sub="common.avg + ' (目标<=5分钟)'"
							:cls="common.success"
						></info_label_compare>
					</el-col>
				</el-row>
			</el-tab-pane>
			<!-- <el-tab-pane label="Submit-build">
				<el-row :gutter="30">
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type4"
							:title="common.titles[0]"
							:num="String(labelsData['submit_build'])"
							:sub="common.subs[0]"
							:to_sub="common.to_sub"
							:cls="common.success"
						></info_label>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label_compare
							:params="generate_label_params(labelsData.submit_day_av_build, [false, 2], 'frequency', common.titles[29], common.type5)"
							:to_sub="common.avg + ' (目标<2)'"
							:sub="common.subs[0]"
							:cls="common.success"
						></info_label_compare>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type5"
							:title="common.titles[28]"
							:num="String(labelsData.submit_build_success)"
							:sub="common.subs[0]"
							:to_sub="common.to_sub"
							:cls="common.success"
						></info_label>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label_compare
							:params="generate_label_params(labelsData.submit_av_success_rate, [true, 90], 'percent', common.titles[27], common.type4)"
							:to_sub="common.avg + ' (目标>=90%)'"
							:sub="common.subs[7]"
							:cls="common.success"
						></info_label_compare>
					</el-col>
				</el-row>
				<el-row :gutter="30">
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type5"
							:title="common.titles[8]"
							:num="formatSeconds(labelsData.submit_av_duration)"
							:sub="common.subs[1]"
							:to_sub="common.avg"
							:cls="common.success"
						></info_label>
					</el-col>
				</el-row>
			</el-tab-pane> -->
			<el-tab-pane label="Verify-build">
				<el-row :gutter="30">
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type4"
							:title="common.titles[0]"
							:num="String(labelsData['verify_build'])"
							:sub="common.subs[0]"
							:to_sub="common.to_sub"
							:cls="common.success"
						></info_label>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label_compare
							:params="generate_label_params(labelsData.verify_day_av_build, [false, 2], 'frequency', common.titles[29], common.type5)"
							:to_sub="common.avg + ' (目标<2)'"
							:sub="common.subs[0]"
							:cls="common.success"
						></info_label_compare>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							id="build16"
							:type="common.type4"
							:title="common.titles[28]"
							:num="String(labelsData.verify_build_success)"
							:sub="common.subs[0]"
							:to_sub="common.to_sub"
							:cls="common.success"
						></info_label>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label_compare
							:params="generate_label_params(labelsData.verify_av_success_rate, [true, 90], 'percent', common.titles[27], common.type5)"
							:to_sub="common.avg + ' (目标>=90%)'"
							:sub="common.subs[7]"
							:cls="common.success"
						></info_label_compare>
					</el-col>
				</el-row>
				<el-row :gutter="30">
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label_compare
								:params="generate_label_params(labelsData.verify_av_duration, [false, 30], 'time', common.titles[8], common.type5)"
								:to_sub="common.avg + ' (目标<=30分钟)'"
								:sub="common.subs[1]"
								:cls="common.success"
							></info_label_compare>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label_compare
								:params="generate_label_params(labelsData.verify_av_queue_time, [false, 5], 'time', common.titles[30], common.type5)"
								:sub="common.subs[1]"
								:to_sub="common.avg + ' (目标<=5分钟)'"
								:cls="common.success"
							></info_label_compare>
						</el-col>
				</el-row>
			</el-tab-pane>
			<el-tab-pane label="Release-build">
				<el-row :gutter="30">
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type4"
							:title="common.titles[0]"
							:num="String(labelsData['release_build'])"
							:sub="common.subs[0]"
							:to_sub="common.to_sub"
							:cls="common.success"
						></info_label>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label_compare
							:params="generate_label_params(labelsData.release_day_av_build, [false, 2], 'frequency', common.titles[29], common.type5)"
							:to_sub="common.avg + ' (目标<2)'"
							:sub="common.subs[0]"
							:cls="common.success"
						></info_label_compare>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type4"
							:title="common.titles[28]"
							:num="String(labelsData.release_build_success)"
							:sub="common.subs[0]"
							:to_sub="common.to_sub"
							:cls="common.success"
						></info_label>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label_compare
							:params="generate_label_params(labelsData.release_av_success_rate, [true, 90], 'percent', common.titles[27], common.type5)"
							:sub="common.subs[7]"
							:to_sub="common.avg + ' (目标>=90%)'"
							:cls="common.success"
						></info_label_compare>
					</el-col>
				</el-row>
				<el-row :gutter="30">
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type5"
							:title="common.titles[8]"
							:num="formatSeconds(labelsData.release_av_duration)"
							:sub="common.subs[1]"
							:to_sub="common.avg"
							:cls="common.success"
						></info_label>
					</el-col>
				</el-row>
			</el-tab-pane>
		</el-tabs>
        <el-tabs type="border-card" style="margin-bottom:20px">
			<el-tab-pane label="代码规范检查">
				<el-row :gutter="30">
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type5"
							title="Clint检查时长"
							:num="formatSeconds(labelsData.av_clint_duration)"
							:sub="common.subs[1]"
							:to_sub="common.avg"
							:cls="common.success"
						></info_label>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type5"
							title="Cpplint检查时长"
							:num="formatSeconds(labelsData.av_cpplint_duration)"
							:sub="common.subs[1]"
							:to_sub="common.avg"
							:cls="common.success"
						></info_label>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type5"
							title="Checkpatch检查时长"
							:num="formatSeconds(labelsData.av_checkpatch_duration)"
							:sub="common.subs[1]"
							:to_sub="common.avg"
							:cls="common.success"
						></info_label>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type5"
							title="Checkstyle检查时长"
							:num="formatSeconds(labelsData.av_checkstyle_duration)"
							:sub="common.subs[1]"
							:to_sub="common.avg"
							:cls="common.success"
						></info_label>
					</el-col>
				</el-row>
			</el-tab-pane>
			<el-tab-pane label="代码静态检查">
				<el-row :gutter="30">
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type5"
							title="Pclint检查时长"
							:num="formatSeconds(labelsData.av_pclint_duration)"
							:sub="common.subs[1]"
							:to_sub="common.avg"
							:cls="common.success"
						></info_label>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type5"
							title="Findbugs检查时长"
							:num="formatSeconds(labelsData.av_findbugs_duration)"
							:sub="common.subs[1]"
							:to_sub="common.avg"
							:cls="common.success"
						></info_label>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type5"
							title="Coverity检查时长"
							:num="formatSeconds(labelsData.av_coverity_duration)"
							:sub="common.subs[1]"
							:to_sub="common.avg"
							:cls="common.success"
						></info_label>
					</el-col>
				</el-row>
			</el-tab-pane>
			<el-tab-pane label="代码质量检查">
				<el-row :gutter="30">
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type5"
							title="Simian检查时长"
							:num="formatSeconds(labelsData.av_simian_duration)"
							:sub="common.subs[1]"
							:to_sub="common.avg"
							:cls="common.success"
						></info_label>
					</el-col>
					<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type5"
							title="Sourcemonitor检查时长"
							:num="formatSeconds(labelsData.av_sourcemonitor_duration)"
							:sub="common.subs[1]"
							:to_sub="common.avg"
							:cls="common.success"
						></info_label>
					</el-col>
				</el-row>
			</el-tab-pane>
		</el-tabs>
		<el-card class="box-card m-b" shadow="never" style="margin-bottom:20px">
			<div slot="header" class="clearfix">
				<span>构建频率趋势</span>
			</div>
			<div>
				<ve-line
				:data="buildChartData"
				:settings="buildChartSettings"
				:data-empty="buildDataEmpty"
				:data-zoom="dataZoom"
				></ve-line>
			</div>
		</el-card>
		<el-card class="box-card m-b" shadow="never" style="margin-bottom:20px">
			<div slot="header" class="clearfix">
				<span>构建效率趋势</span>
			</div>
			<div>
				<ve-line
					:data="durationChartData"
					:settings="durationChartSettings"
					:data-empty="durationDataEmpty"
					:data-zoom="dataZoom"
				></ve-line>
			</div>
		</el-card>
		<!-- <el-card class="box-card m-b" shadow="never" style="margin-bottom:20px">
			<div slot="header" class="clearfix">
				<span>节点负载</span>
			</div>
			<div>
				<el-row>
					<el-form :inline="true">
						<el-col :span="8">
							<el-form-item label="Jenkins IP" label-width="100px">
								<el-select v-model="selectedIP" placeholder="请选择Jenkins IP" clearable>
									<el-option v-for="(ip, index) in table_load.ips" :key="index" :label="ip" :value="ip"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :span="8">
							<el-form-item label="构建类型" label-width="100px">
								<el-select v-model="selectedBuild" placeholder="请选择构建类型" clearable>
									<el-option
										v-for="(build, index) in table_load.build_list"
										:key="index"
										:label="build"
										:value="build"
									></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :span="8">
							<el-form-item label="Job名" label-width="100px">
								<el-select v-model="selectedJob" placeholder="请选择Job名" clearable>
									<el-option
										v-for="(job, index) in table_load.job_list"
										:key="index"
										:label="job"
										:value="job"
									></el-option>
								</el-select>
							</el-form-item>
						</el-col>
					</el-form>
				</el-row>
				<el-table
					:data="table_load.details"
					style="width: 100%; margin-bottom: 20px"
					show-summary
					:summary-method="getSummaries"
				>
					<el-table-column type="expand">
						<template slot-scope="scope">
							<el-form label-position="left" inline class="demo-table-expand">
								<el-form-item label="Daily-build次数">
									<span>{{ scope.row.daily_build_num }}个</span>
								</el-form-item>
								<el-form-item label="Verify-build次数">
									<span>{{ scope.row.verify_build_num }}个</span>
								</el-form-item>
								<el-form-item label="代码下载平均时长">
									<span>{{ formatSeconds(scope.row.avg_sync_time) }}</span>
								</el-form-item>
								<el-form-item label="AMSS平均时长">
									<span>{{ formatSeconds(scope.row.avg_amss_time) }}</span>
								</el-form-item>
								<el-form-item label="Android平均时长">
									<span>{{ formatSeconds(scope.row.avg_android_time) }}</span>
								</el-form-item>
								<el-form-item label="QNX平均时长">
									<span>{{ formatSeconds(scope.row.avg_qnx_time) }}</span>
								</el-form-item>
							</el-form>
						</template>
					</el-table-column>
					<el-table-column prop="nodeIP" label="节点 IP"></el-table-column>
					<el-table-column prop="build_num" label="构建数" sortable></el-table-column>
					<el-table-column prop="build_rate" label="构建占用率" sortable></el-table-column>
					<el-table-column prop="av_build_time" label="平均构建时间" sortable></el-table-column>
					<el-table-column prop="jenkinsIP" label="Jenkins IP"></el-table-column>
				</el-table>
				<el-pagination
					style="text-align: center"
					background
					layout="prev, pager, next"
					@current-change="handleCurrentChange"
					:total="buildCount"
					:page-count="table_load.num_pages"
				></el-pagination>
			</div>
		</el-card> -->
		<el-card class="box-card m-b" shadow="never">
			<div slot="header" class="clearfix">
				<span>日统计汇总</span>
			</div>
			<div>
				<el-table
					:data="currentData"
					border
					style="width: 100%; margin-bottom: 20px"
					@sort-change="sortChange"
				>
					<el-table-column prop="update_date" label="日期" width="100px" sortable></el-table-column>
					<el-table-column prop="build" label="构建" width="80px" sortable></el-table-column>
					<el-table-column prop="daily_av_duration" label="Daily-build平均构建时长" sortable></el-table-column>
					<el-table-column prop="release_av_duration" label="Release-build平均构建时长" sortable></el-table-column>
					<el-table-column prop="submit_av_duration" label="Submit-build平均构建时长" sortable></el-table-column>
					<el-table-column prop="verify_av_duration" label="Verify-build平均构建时长" sortable></el-table-column>
					<el-table-column prop="av_build_passrate" label="平均构建成功率" width="120px" sortable></el-table-column>
					<el-table-column label="详情" width="120px">
						<template slot-scope="scope">
							<el-button
								type="primary"
								plain
								@click="viewDetail(scope.$index, scope.row)"
								size="medium"
							>查看详情</el-button>
						</template>
					</el-table-column>
				</el-table>
				<el-pagination
					@size-change="handleSizeChange"
					@current-change="handleDailyCurrentChange"
					:current-page="currentDailyPage"
					:page-sizes="[10, 15, 50, 100]"
					:page-size="currentSize"
					layout="total, sizes, prev, pager, next, jumper"
					:total="totalCount"
				></el-pagination>
			</div>
		</el-card>
    </div>
</template>

<script>
import { pagingData } from './utils.js';
import info_label from '@/components/devops/info_label.vue';
import info_label_compare from '@/components/devops/info_label_compare.vue';
import common from '@/components/devops/get_data';
import { getHeader } from '@/app.config';
import 'echarts/lib/component/dataZoom';
import 'v-charts/lib/style.css';
export default {
    data() {
		this.dataZoom = [{
			type: 'slider',
			start: 0,
			end: 100
		}];
		return {
			common,
			ips: [],
			total_build: 0,
			table_load: Object,
			buildCount: 1,
			selectedIP: '',
			selectedBuild: '',
			changeTab: 0,
			selectedJob: '',
			currentDate: '',
			currentPage: 1,
			currentDailyPage: 1,
			currentSize: 10,
			buildDataEmpty: true,
			durationDataEmpty: true,
			currentData: [],
			totalCount: 0,
			tableData: [],
			buildChartData: {
				columns: [
					'update_date',
					'build',
					'daily_build',
					'submit_build',
					'verify_build',
					'release_build'
				],
				rows: []
			},
			durationChartData: {
				columns: [
					'update_date',
					'daily_av_duration',
					'submit_av_duration',
					'verify_av_duration',
					'release_av_duration'
				],
				rows: []
			},
			buildChartSettings: {
				labelMap: {
					build: 'Total',
					daily_build: 'Daily-build',
					submit_build: 'Submit-build',
					verify_build: 'Verify-build',
					release_build: 'Release-build'
				}
			},
			durationChartSettings: {
				labelMap: {
					daily_av_duration: 'Daily-build平均时长',
					submit_av_duration: 'Submit-build平均时长',
					verify_av_duration: 'Verify-build平均时长',
					release_av_duration: 'Release-build平均时长'
				}
			},
			labelsData: {},
		};
	},
	components: {
		info_label,
		info_label_compare,
    },
    props: {
        params: Object
    },
    methods: {
		init_datas: function(projectId, dates) {
			this.get_daily_summary(projectId, dates);
			// this.get_load_data(projectId, dates);
			this.get_data_by_url(projectId, dates);
		},
		filterObject: function(filterChange) {
			console.log('1111')
		},
		sortChange: function(val) {
			var key = val['prop'];
			var compare1 = function(obj1, obj2) {
				var val1 = obj1[key];
				var val2 = obj2[key];
				if (val1 < val2) {
					return -1;
				} else if (val1 > val2) {
					return 1;
				} else {
					return 0;
				}
			};
			var compare2 = function(obj1, obj2) {
				var val1 = obj1[key];
				var val2 = obj2[key];
				if (val1 < val2) {
					return 1;
				} else if (val1 > val2) {
					return -1;
				} else {
					return 0;
				}
			};
			var arr = this.tableData;
			if (val['order'] === 'ascending') {
                this.currentData = pagingData(arr.sort(compare2), this.totalCount, this.currentDailyPage, this.currentSize);
			} else if (val['order'] === 'descending') {
                this.currentData = pagingData(arr.sort(compare2), this.totalCount, this.currentDailyPage, this.currentSize);
			} else {
				key = 'update_date';
                this.currentData = pagingData(arr.sort(compare2), this.totalCount, this.currentDailyPage, this.currentSize);
			}
		},
		handleSizeChange: function(size) {
			this.currentSize = size;
            this.currentData = pagingData(this.tableData, this.totalCount, this.currentDailyPage, this.currentSize);
		},
		handleDailyCurrentChange: function(page) {
			this.currentDailyPage = page;
            this.currentData = pagingData(this.tableData, this.totalCount, this.currentDailyPage, this.currentSize);
		},
		viewDetail(index, row) {
			let routeData = this.$router.resolve({
				path:
					'/project/details/' +
					this.params.projectId + '/' +
					this.params.projectName +
					'_@_' +
					row.update_date +
					'_@_buildinfo'
			});
			window.open(routeData.href, '_blank');
		},
		// handleCurrentChange(val) {
		// 	this.currentPage = val;
		// 	const dates = this.params.time === 'undefined' ? '' : this.params.time;
		// 	const projectId = val.projectId === 'undefined' ? '' : this.params.projectId;
		// 	this.get_load_data(projectId, dates);
		// },
		getSummaries(param) {
			const { columns, data } = param;
			const sums = [];
			columns.forEach((column, index) => {
				if (index === 1) {
					sums[index] = '总构建次数';
					return;
				} else if (index === 3) {
					sums[index] = '总平均构建时间';
					return;
				} else if (index === 0 || index === 5) {
					return;
				} else if (index === 2) {
					const values = data.map(item =>
						Number(item[column.property].split('个')[0])
					);
					if (!values.every(value => isNaN(value))) {
						sums[index] = values.reduce((prev, curr) => {
							const value = Number(curr);
							if (!isNaN(value)) {
								return prev + curr;
							} else {
								return prev;
							}
						}, 0);
						sums[index] += '个';
					} else {
						sums[index] = '';
					}
				} else {
					const values = data.map(item =>
						Number(item[column.property].split('秒')[0])
					);
					if (!values.every(value => isNaN(value))) {
						sums[index] = values.reduce((prev, curr) => {
							const value = Number(curr);
							if (!isNaN(value)) {
								return prev + curr;
							} else {
								return prev;
							}
						}, 0);
						sums[index] = this.formatSeconds(
							parseInt(sums[index] / values.length)
						);
					} else {
						sums[index] = '';
					}
				}
			});
			return sums;
		},
		update_ui: function() {
			this.$refs.build_info_table.update_data(
				this.labelsData.table_summary_data
			);
			if (!this.first) {
				this.$refs.chart5.update_data(this.labelsData.chart_data);
				this.$refs.chart6.update_data(this.labelsData.chart_data);
			}
			this.first = false;
		},
		get_load_data: function(projectId, date) {
			var url =
				process.env.VUE_APP_KANBAN_HOST +
				'/api/devops/load?projectId=' +
				projectId +
				'&ip=' +
				this.selectedIP +
				'&build_type=' +
				this.selectedBuild +
				'&job=' +
				this.selectedJob +
				'&date=' +
				date +
				'&page=' +
				this.currentPage;
			var _self = this;
			this.$axios.get(url, {headers: getHeader()}).then(function(response) {
				if (response.status === 200) {
					if (response.data.code === 200) {
						_self.table_load = response.data;
						_self.buildCount = _self.table_load.count;
						for (var i = 0; i < _self.table_load.details.length; i++) {
							_self.pageValue = false;
							_self.table_load.details[i]['build_num'] += ' 个';
							_self.table_load.details[i]['build_rate'] += ' %';
							if (_self.table_load.details[i]['av_build_time'] > 60) {
								_self.table_load.details[i]['av_build_time'] =
									_self.table_load.details[i]['av_build_time'] +
									'秒' +
									'(' +
									_self.formatSeconds(
										_self.table_load.details[i]['av_build_time']
									) +
									')';
							} else {
								_self.table_load.details[i]['av_build_time'] =
									_self.table_load.details[i]['av_build_time'] + '秒';
							}
						}
					} else {
						_self.table_load = {};
						_self.buildCount = 0;
					}
				}
			});
		},
		get_data_by_url: function(projectId, dates) {
			this.labelsData = {};
			var self = this;
			this.$axios
				.get(
					process.env.VUE_APP_KANBAN_HOST +
						'/api/devops/project/summary?page=build&projectId=' +
						projectId +
						'&date=' +
						dates,
					{headers: getHeader()}
				)
				.then(function(response) {
					if (response.status == 200) {
						if (response.data.code === 200) {
							var data = response.data;
							self.labelsData = data.data;
						}
					}
				})
				.catch(function(err) {
					console.log(err);
				});
		},
		get_daily_summary(projectId, dates) {
			this.currentData = [];
			this.tableData = [];
			this.totalCount = 0;
			this.buildChartData.rows = [];
			this.durationChartData.rows = [];
			this.buildDataEmpty = true;
			this.durationDataEmpty = true;
			var self = this;
			this.$axios
				.get(
					process.env.VUE_APP_KANBAN_HOST +
						'/api/devops/project/table/summary?projectId=' +
						projectId +
						'&date=' +
						dates +
						'&page=build',
						{headers: getHeader()}
				)
				.then(function(response) {
					if (response.status == 200) {
						if (response.data.code === 200 && response.data.data.length > 0) {
							var data = response.data.data;
							for (var i = 0; i < data.length; i++) {
								var tableDict = {
									update_date: data[i]['update_date'],
									build: data[i]['build'] + '次',
									daily_av_duration: self.formatSeconds(
										data[i]['daily_av_duration']
									),
									release_av_duration: self.formatSeconds(
										data[i]['release_av_duration']
									),
									submit_av_duration: self.formatSeconds(
										data[i]['submit_av_duration']
									),
									verify_av_duration: self.formatSeconds(
										data[i]['verify_av_duration']
									),
									av_build_passrate: data[i]['av_build_passrate'] + '%'
								};
								self.tableData.push(tableDict);
							}
							self.totalCount = self.tableData.length;
							self.currentDailyPage = 1;
							self.currentSize = 10;
							self.buildDataEmpty = false;
							self.durationDataEmpty = false;
							if (self.totalCount === 0) {
								self.currentData = [];
								self.buildDataEmpty = true;
								self.durationDataEmpty = true;
							} else {
								self.currentData = pagingData(self.tableData, self.totalCount, self.currentDailyPage, self.currentSize);
							}
							let chartData = data.reverse();
							self.buildChartData.rows = chartData;
							self.durationChartData.rows = chartData;
						}
					}
				})
				.catch(function(err) {
					console.log(err);
				});
		},
		fomatFloat(src, pos) {
			return Math.round(src * Math.pow(10, pos)) / Math.pow(10, pos);
		},
		generate_label_params: function(val1, val2, dataType, dataTitle, label) {
			if (typeof val1 === 'undefined') {
				val1 = 0;
			}
			var labelParam;
			if (dataType === 'time') {
				var standardTime = val2[1] * 60;
				if (val1) {
					if (val2[0]) {
						labelParam = {
							type: label,
							title: dataTitle,
							num: this.formatSeconds(val1),
							status: val1 > standardTime ? 'reach' : 'down',
							difference:
								val1 > standardTime
									? ''
									: this.formatSeconds(standardTime - val1)
						};
					} else {
						labelParam = {
							type: label,
							title: dataTitle,
							num: this.formatSeconds(val1),
							status: val1 > standardTime ? 'up' : 'reach',
							difference:
								val1 > standardTime
									? this.formatSeconds(val1 - standardTime)
									: ''
						};
					}
				} else {
					labelParam = {
						type: label,
						title: dataTitle,
						num: this.formatSeconds(val1),
						status: 'reach',
						difference: ''
					};
				}
				return labelParam;
			} else if (dataType === 'percent') {
				if (val1) {
					if (val2[0]) {
						labelParam = {
							type: label,
							title: dataTitle,
							status: val1 > val2[1] ? 'reach' : 'down',
							difference:
								val1 > val2[1] ? '' : this.fomatFloat(val2[1] - val1, 2) + '%',
							num: this.fomatFloat(val1, 2)
						};
					} else {
						labelParam = {
							type: label,
							title: dataTitle,
							status: val1 > val2[1] ? 'up' : 'reach',
							difference:
								val1 > val2[1] ? this.fomatFloat(val1 - val2[1], 2) + '%' : '',
							num: this.fomatFloat(val1, 2)
						};
					}
				} else {
					labelParam = {
						type: label,
						title: dataTitle,
						status: 'reach',
						difference: '',
						num: this.fomatFloat(val1, 2)
					};
				}
				return labelParam;
			} else if (dataType === 'frequency') {
				if (val1) {
					if (val2[0]) {
						labelParam = {
							type: label,
							title: dataTitle,
							num: this.fomatFloat(val1, 2),
							status: val1 > val2[1] ? 'reach' : 'down',
							difference:
								val1 > val2[1] ? '' : this.fomatFloat(val2[1] - val1, 2)
						};
					} else {
						labelParam = {
							type: label,
							title: dataTitle,
							num: this.fomatFloat(val1, 2),
							status: val1 > val2[1] ? 'up' : 'reach',
							difference:
								val1 > val2[1] ? this.fomatFloat(val1 - val2[1], 2) : ''
						};
					}
				} else {
					labelParam = {
						type: label,
						title: dataTitle,
						num: this.fomatFloat(val1, 2),
						status: 'reach',
						difference: ''
					};
				}
				return labelParam;
			} else if (dataType === 'multiple') {
				if (val1) {
					if (val2[0]) {
						labelParam = {
							type: label,
							title: dataTitle,
							num: this.fomatFloat(val1, 2),
							status: val1 > val2[1] ? 'reach' : 'down',
							difference:
								val1 > val2[1] ? '' : this.fomatFloat(val2[1] - val1, 2)
						};
					} else {
						labelParam = {
							type: label,
							title: dataTitle,
							num: this.fomatFloat(val1, 2),
							status: val1 > val2[1] ? 'up' : 'reach',
							difference:
								val1 > val2[1] ? this.fomatFloat(val1 - val2[1], 2) : ''
						};
					}
				} else {
					labelParam = {
						type: label,
						title: dataTitle,
						num: this.fomatFloat(val1, 2),
						status: 'reach',
						difference: ''
					};
				}
				return labelParam;
			} else {
				labelParam = {
					type: label,
					title: dataTitle,
					num: this.fomatFloat(val1, 2),
					status: 'reach',
					difference: ''
				};
				return labelParam;
			}
		},
		formatSeconds(value) {
			if (isNaN(value)) {
				value = 0;
			}
			var theTime = parseInt(value); // 秒
			var theTime1 = 0; // 分
			var theTime2 = 0; // 小时
			var theTime3 = 0; // 天
			if (theTime > 60) {
				theTime1 = parseInt(theTime / 60);
				theTime = parseInt(theTime % 60);
				if (theTime1 > 60) {
					theTime2 = parseInt(theTime1 / 60);
					theTime1 = parseInt(theTime1 % 60);
					if (theTime2 > 24) {
						theTime3 = parseInt(theTime2 / 24);
						theTime2 = parseInt(theTime2 % 24);
					}
				}
			}
			var result = '' + parseInt(theTime) + '秒';
			if (theTime1 > 0) {
				result = '' + parseInt(theTime1) + '分' + result;
			}
			if (theTime2 > 0) {
				result = '' + parseInt(theTime2) + '时' + result;
			}
			if (theTime3 > 0) {
				result = '' + parseInt(theTime3) + '天' + result;
			}
			return result;
		},
    },
    watch: {
        params: {
			handler: function(val) {
                const projectId = val.projectId === 'undefined' ? '' : val.projectId;
                const dates = val.time === 'undefined' ? '' : val.time;
				this.init_datas(projectId, dates);
			},
			deep: true
        }
    //     selectedIP: function(val) {
		// 	const dates = this.params.time === 'undefined' ? '' : this.params.time;
		// 	const projectId = val.projectId === 'undefined' ? '' : this.params.projectId;
		// 	this.get_load_data(projectId, dates);
		// },
		// selectedBuild: function(val) {
		// 	const dates = this.params.time === 'undefined' ? '' : this.params.time;
		// 	const projectId = val.projectId === 'undefined' ? '' : this.params.projectId;
		// 	this.get_load_data(projectId, dates);
		// },
		// selectedJob: function(val) {
		// 	const dates = this.params.time === 'undefined' ? '' : this.params.time;
		// 	const projectId = val.projectId === 'undefined' ? '' : this.params.projectId;
    //         this.get_load_data(projectId, dates);
    //     }
    },
    mounted() {
        const projectId = this.params.projectId === 'undefined' ? '' : this.params.projectId;
        const dates = this.params.time === 'undefined' ? '' : this.params.time;
		this.init_datas(projectId, dates);
	}
}
</script>
